//
//  ZLExciseBeginViewController.m
//  ZLExamination
//
//  Created by leilei on 2017/9/3.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLExciseBeginViewController.h"
#import "ZLExciseBeginHeaderView.h"
#import "ZLExciseBeginFooterView.h"
#import "ZLExciseBeginCollectionViewCell.h"
#import "ZLExciseBeginModel.h"
#import "ZlExciseBeginSheetViewController.h"
#import "ZLBaseNavigationController.h"
#import "ZLExamBeginExitPromptView.h"
#import "ZLExamBeginSheetCommitView.h"
#import "ZLBaseNavigationController.h"

static NSString *const ZLExciseBeginCollectionViewSingleCellID = @"ZLExciseBeginCollectionViewSingleCellID";
static NSString *const ZLExciseBeginCollectionViewMultipleCellID = @"ZLExciseBeginCollectionViewMultipleCellID";

@interface ZLExciseBeginViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
/** 练习标题view*/
@property (nonatomic, strong) ZLExciseBeginHeaderView *headerView;
/** 最下面按钮view*/
@property (nonatomic, strong) ZLExciseBeginFooterView *footerView;
/** 练习题collectionview*/
@property (nonatomic, strong) UICollectionView *bgCollectionView;
@property (nonatomic, strong) ZLExamBeginExitPromptView *promptView; //退出提示
@property (nonatomic, strong) ZLExamBeginSheetCommitView *commitView; //交卷提示
@property (nonatomic) NSUInteger pageNumber; //当前页数
@property (nonatomic) NSUInteger totalPageNumber; //总页数

@property (nonatomic, copy) NSArray<NSMutableArray *> *totalQuestions; //单选多选 总
@property (nonatomic, strong) NSMutableArray<ZLExciseBeginModel *> *singles; //单选答案集合
@property (nonatomic, strong) NSMutableArray<ZLExciseBeginModel *> *multiples; ///多选答案集合
@property (nonatomic, copy) NSArray<NSString *> *questionTitles; //选项
@property (nonatomic) dispatch_source_t timer; //计时线程
@property (nonatomic) NSInteger beginTime; //开始秒数
@property (nonatomic) NSInteger currentTime; //剩余秒数
/** 所有题的考试答案数组*/
@property (nonatomic,strong) NSMutableArray* allAnswerArray;
/** 暂停题目ID*/
@property (nonatomic,strong) NSNumber* suspend_qid;
/** 练习成绩*/
@property (nonatomic,copy) NSString* scoreStr;
/** 练习题每道题 model*/
@property (nonatomic,strong) ZLExciseBeginModel* exciseListModel;
/** 无数据退出提示*/
@property (nonatomic,strong) ZLExamBeginExitPromptView* noDataExitView;
@end

@implementation ZLExciseBeginViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _questionTitles = @[@"A",@"B",@"C",@"D"];
    _pageNumber = 1;
    //添加子视图
    [self subviewsInView];
    [self listLoadData];
    //用户点击事件
    [self myClickAction];
    
}

#pragma mark - 数据请求
- (void)listLoadData
{
    NSString *curriculum_id = _model.curriculum_id;
    NSString *chapter_id = _model.k_id;
    _singles = [NSMutableArray array];
    _multiples = [NSMutableArray array];
    NSDictionary *param = @{@"curriculum_id":@([curriculum_id intValue]),
                            @"chapter_id" : @([chapter_id intValue])
                            };
    NSLog(@"%@ --%@", @([curriculum_id intValue]), @([chapter_id intValue]));
    YCRequestDataService *manager = [YCRequestDataService sharedManager];
    [manager Post:@"curriculum/exercises/lists" parameters:param success:^(id response) {
        NSLog(@"%@", response);
        if (response[@"error_code"]) {
            NSLog(@"%@",response[@"error_msg"]);
            _noDataExitView.titleLbl.text = response[@"error_msg"];
            [_noDataExitView showExitPromptView];
//            [manager showHUDSleepText:self withTitle:response[@"error_msg"]];
        } else {
            //设置总页数
//            _totalPageNumber = [response[@"response_data"][@"count"] integerValue];
            NSArray<NSDictionary *> *lists = response[@"response_data"][@"lists"];
            _totalPageNumber = lists.count;
            [lists enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                ZLExciseBeginModel *exciseModel = [[ZLExciseBeginModel alloc] initWithDataDic:obj];
                //单选或者多选
                if ([exciseModel.type integerValue] == 1) {
                    exciseModel.questionNumber = @(idx);
                    exciseModel.isSingles = YES;
//                    //TODO:(单选)继续考试给每个选项传值
                    exciseModel.questionAnswer = exciseModel.the_answer;
                    [_singles addObject:exciseModel];
                    
                } else if ([exciseModel.type integerValue] == 2) {
                    exciseModel.questionNumber = @(idx);
                    exciseModel.isSingles = NO;
                    //TODO:(单选)继续考试给每个选项传值???

                    [_multiples addObject:exciseModel];
                }
            }];
            if (_singles.count != 0 || _multiples.count != 0) {
                _totalQuestions = @[_singles,_multiples];
                
                //设置显示页数
                [self setDisplayPageNumber];
                
//                //计时开始
//                [self examTimeCalculationWithSeconds:arc4random()%4000];
                [_bgCollectionView reloadData];
            } else {
                [manager showHUDSleepText:self withTitle:response[@"暂无数据"]];
            }
        }
    } failure:^{
        NSLog(@"网络或服务器出错");
    }];
}

#pragma mark - 点击事件
- (void)myClickAction
{
    __weak typeof(self) weakSelf = self;
    //上一页操作
    [_footerView setLeftClick:^{
        kCX_LOG(@"向上");
        if (_pageNumber > 1) {
            weakSelf.pageNumber --;
            [weakSelf setDisplayPageNumber];
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_pageNumber-1 inSection:0];
            //滚到下角标的位置
            [weakSelf.bgCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
        }
    }];
    
    //下一页操作
    [_footerView setRightClick:^{
        if (_pageNumber == _totalPageNumber) {
            ZlExciseBeginSheetViewController *exciseSheetVC = [[ZlExciseBeginSheetViewController alloc] init];
            exciseSheetVC.questions = weakSelf.totalQuestions;
            NSString *curriculum_id = weakSelf.model.curriculum_id;
            NSString *chapter_id = weakSelf.model.k_id;
            exciseSheetVC.curriculum_id = @([curriculum_id intValue]);
            exciseSheetVC.chapter_id = @([chapter_id intValue]);
            //退出的时候 先暂停考试,再退出
            [weakSelf paperScore];
            exciseSheetVC.questions_id = weakSelf.suspend_qid;
            exciseSheetVC.scoreStr = weakSelf.scoreStr;
            exciseSheetVC.model = weakSelf.model;
            //通过答题卡的回调方法, 选择题目
            exciseSheetVC.clickCallBack = ^(NSInteger number) {
                [weakSelf scroolToDesignationRowWith:number];
            };
            [weakSelf.navigationController pushViewController:exciseSheetVC animated:YES];
            
            return;
        }
        if (_pageNumber < _totalPageNumber) {
            weakSelf.pageNumber++;
            [weakSelf setDisplayPageNumber];
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_pageNumber-1 inSection:0];
            [weakSelf.bgCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
        }
    }];
    
    //答题卡操作
    [_footerView setSheetClick:^{
        ZlExciseBeginSheetViewController *exciseSheetVC = [[ZlExciseBeginSheetViewController alloc] init];
        exciseSheetVC.questions = weakSelf.totalQuestions;
        NSLog(@"%@", weakSelf.totalQuestions);
        NSString *curriculum_id = weakSelf.model.curriculum_id;
        NSString *chapter_id = weakSelf.model.k_id;
        exciseSheetVC.curriculum_id = @([curriculum_id intValue]);
        exciseSheetVC.chapter_id = @([chapter_id intValue]);
        NSLog(@"%@ --%@", @([curriculum_id intValue]), @([chapter_id intValue]));
        //退出的时候 先暂停考试,再退出
        [weakSelf paperScore];
        exciseSheetVC.questions_id = weakSelf.suspend_qid;
        exciseSheetVC.scoreStr = weakSelf.scoreStr;
        exciseSheetVC.model = weakSelf.model;
        //通过答题卡的回调方法, 选择题目
        exciseSheetVC.clickCallBack = ^(NSInteger number) {
            [weakSelf scroolToDesignationRowWith:number];
        };
        [weakSelf.navigationController pushViewController:exciseSheetVC animated:YES];

    }];
    
    //退出弹窗确定退出考试
    [self.promptView setEnterCallBack:^{
        //如果有数据
//        dispatch_source_cancel(weakSelf.timer);
//        weakSelf.headerView.timeLbl.hidden = YES;
        [weakSelf.headerView.timeLbl removeFromSuperview];
        weakSelf.headerView.timeLbl = nil;
        //退出的时候 先暂停考试,再退出
        [weakSelf paperScore];
        //提交暂停信息
        [weakSelf pauseExamLoadDataWith:weakSelf.scoreStr];
        
        [weakSelf dismissViewControllerAnimated:YES completion:nil];
    }];
    
    //自动交卷
    [_commitView setEnterCallBack:^{
        kCX_LOG(@"自动交卷");
    }];
    
    //数据有问题, 弹窗点击退出
    [_noDataExitView setEnterCallBack:^{
        [weakSelf dismissViewControllerAnimated:YES completion:nil];
    }];
}
//计算试卷成绩
- (void)paperScore
{
    _allAnswerArray = [NSMutableArray array];
    NSMutableArray<ZLExciseBeginModel *> *singleArr = _totalQuestions[0];
    NSMutableArray<ZLExciseBeginModel *> *multipleArr = _totalQuestions[1];
    //打印单选选择的内容
    [singleArr enumerateObjectsUsingBlock:^(ZLExciseBeginModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.questionAnswer) {
            NSString *answerStr = [NSString stringWithFormat:@"%ld:%@", idx + 1, obj.questionAnswer];
            [_allAnswerArray addObject:answerStr];
        } else {
            NSString *answerStr = [NSString stringWithFormat:@"%ld: ", idx + 1];
            [_allAnswerArray addObject:answerStr];
        }
    }];
    
    //打印多选选择的内容
    [multipleArr enumerateObjectsUsingBlock:^(ZLExciseBeginModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.answers.count != 0) {
            
            //obj.answers数组里面按照abcd 排序 后放到resultArray数组里
            NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch|NSNumericSearch|
            NSWidthInsensitiveSearch|NSForcedOrderingSearch;
            
            NSComparator sort = ^(NSString *obj1,NSString *obj2){
                
                NSRange range = NSMakeRange(0,obj1.length);
                
                return [obj1 compare:obj2 options:comparisonOptions range:range];
            };
            NSArray *resultArray = [obj.answers sortedArrayUsingComparator:sort];
            //                obj.answers
            NSString *tempStr = [resultArray componentsJoinedByString:@";"];
            NSString *answerStr = [NSString stringWithFormat:@"%@:%@", obj.n_id, tempStr];
            [_allAnswerArray addObject:answerStr];
            
        } else {
            NSString *answerStr = [NSString stringWithFormat:@"%@: ", obj.n_id];
            [_allAnswerArray addObject:answerStr];
        }
        
    }];
    
    NSString *scoreStr = [_allAnswerArray componentsJoinedByString:@"|"];
    _scoreStr = scoreStr;
    NSLog(@"!!!%@", scoreStr);
    //获取当前页码的 题库的题号
    if (_pageNumber <= _singles.count) {
        [_singles enumerateObjectsUsingBlock:^(ZLExciseBeginModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (_pageNumber == idx + 1) {
                *stop = YES;
                _suspend_qid = @(obj.n_id.intValue);
            }
        }];
    } else {
        [_multiples enumerateObjectsUsingBlock:^(ZLExciseBeginModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (_pageNumber == _singles.count + idx + 1) {
                *stop = YES;
                _suspend_qid = @(obj.n_id.intValue);
            }
        }];
    }
}

#pragma mark - 暂停网络请求
- (void)pauseExamLoadDataWith: (NSString *)scoreStr
{
    //暂停数据请求
    NSString *curriculum_id = _model.curriculum_id;
    NSString *chapter_id = _model.k_id;
    _singles = [NSMutableArray array];
    _multiples = [NSMutableArray array];
    NSDictionary *param = @{@"curriculum_id":@([curriculum_id intValue]),
                            @"chapter_id" : @([chapter_id intValue]),
                            @"score" : scoreStr,
                            @"suspend_qid" : _suspend_qid
                            };
    NSLog(@"%@", param);
    YCRequestDataService *manager = [YCRequestDataService sharedManager];
    [manager Post:@"curriculum/exercises/suspend_exercises" parameters:param success:^(id response) {
        if (response[@"error_code"]) {
            NSLog(@"%@",response[@"error_msg"]);
            [manager showHUDSleepText:self withTitle:response[@"error_msg"]];
        } else {
            
        }
        
    } failure:^{
        NSLog(@"网络或服务器出错");
    }];
    
}

#pragma mark - 设置显示页数
- (void)setDisplayPageNumber {
    _headerView.titleLbl.text = _pageNumber>_singles.count? @"多项选择题":@"单项选择题";
    NSString *selectedNumber = [NSString stringWithFormat:@"%lu",_pageNumber];
    NSString *totalNumber = [NSString stringWithFormat:@"%lu",_totalPageNumber];
    //选中的数字变为蓝色
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@/%@",selectedNumber,totalNumber]];
    NSRange range = NSMakeRange([selectedNumber length], [totalNumber length]+1);
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:range];
    _headerView.numberLbl.attributedText = str;
}

//答题操作    (collectionCell中的tableview 点击事件传递过来的数据 item 第几题  answer 选择第几个)
- (void)answerWithQuestionNumber:(NSInteger)item withAnswerNumber:(NSInteger)answer {
    kCX_LOG(@"第%ld题, 选项%ld",item,answer);

    //单选
    if (item < _singles.count) {
        [_singles enumerateObjectsUsingBlock:^(ZLExciseBeginModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            //选择的题 是当前的题目
            if (item == obj.questionNumber.integerValue) {
                //如果obj.questionAnswer之前的选项与_questionTitles[answer]当前选的不同, 赋值给model 里面
                if (![obj.questionAnswer isEqualToString:_questionTitles[answer]]) {
                    obj.questionAnswer = _questionTitles[answer];
                    obj.isAnswer = YES;
                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:item inSection:0];
                    //单独刷新第几题的item
                    [_bgCollectionView reloadItemsAtIndexPaths:@[indexPath]];
                }
            }
        }];
        //多选
    } else {
        [_multiples enumerateObjectsUsingBlock:^(ZLExciseBeginModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            //题号是当前答题的题号
            if (item == obj.questionNumber.integerValue) {
                //答案数组=0
                if (obj.answers.count == 0) {
                    obj.answers = [NSMutableArray array];
                    [obj.answers addObject:_questionTitles[answer]];
                    //答案数组!=0
                } else {
                    //点击已经选过的 取消选中
                    if ([obj.answers containsObject:_questionTitles[answer]]) {
                        [obj.answers removeObject:_questionTitles[answer]];
                        //点击没选过的  放入选中数组中
                    } else {
                        [obj.answers addObject:_questionTitles[answer]];
                    }
                }
                //答案数组>0 此题已经回答过
                if (obj.answers.count > 0) {
                    obj.isAnswer = YES;
                } else {
                    obj.isAnswer = NO;
                }
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:item inSection:0];
                [_bgCollectionView reloadItemsAtIndexPaths:@[indexPath]];
            }
        }];
    }
}
#pragma mark 跳转到固定题号的位置
- (void)scroolToDesignationRowWith:(NSInteger)rowNumber {
    _pageNumber = rowNumber+1;
    [self setDisplayPageNumber];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowNumber inSection:0];
    [_bgCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
};

#pragma mark - 考试时间计算
- (void)examTimeCalculationWithSeconds:(NSInteger)seconds {
    _headerView.timeLbl.text = [self getExamTimeWithSeconds:seconds];
    __block NSInteger timeout = seconds;
//    全局队列是并发队列
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    //1.1将定时器设置在主线程
    _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    //1.2设置定时器每一秒执行一次
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0), 1.0*NSEC_PER_SEC, 0);
    //1.3设置定时器执行的动作
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout <= 0){
            //结束定时
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                [self timeOverToAutoCommitExam];
            });
            
        } else {
            timeout--;
        }
        //异步加载 显示定时器时间
        dispatch_async(dispatch_get_main_queue(), ^{
            _headerView.timeLbl.text = [self getExamTimeWithSeconds:timeout];
        });
        
        _currentTime = timeout;
    });
    //启动定时器
    dispatch_resume(_timer);
}

- (NSString *)getExamTimeWithSeconds:(NSInteger)seconds {
    NSInteger hour = seconds/3600;
    NSInteger minute = seconds%3600/60;
    NSInteger second = seconds%3600%60;
    NSString *hourStr = [NSString stringWithFormat:@"0%ld",hour];
    NSString *minuteStr = minute < 10 ? [NSString stringWithFormat:@"0%ld",minute]:[NSString stringWithFormat:@"%ld",minute];
    NSString *secondStr = second < 10 ? [NSString stringWithFormat:@"0%ld",second]:[NSString stringWithFormat:@"%ld",second];
    NSString *timeStr = [NSString stringWithFormat:@"%@:%@:%@",hourStr,minuteStr,secondStr];
    return timeStr;
}

#pragma mark 自动交卷
- (void)timeOverToAutoCommitExam {
    [_commitView showCommitViewAutoCommit];
}

#pragma mark 左上角返回键退出考试
- (void)backBarButtonPressed:(id)sender {
    kCX_LOG(@"是否退出");
    [_promptView showExitPromptView];
}

#pragma mark - scrollview delegate
//滑动翻页
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger index = (NSInteger)scrollView.contentOffset.x/(NSInteger)kSCREEN_WIDTH+1;
    if (_pageNumber != index) {
        _pageNumber = index;
        [self setDisplayPageNumber];
    }
}


#pragma mark - collectionview datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _totalPageNumber;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    __weak typeof(self) weakSelf = self;
    if (indexPath.item < _singles.count) {
        //单选
        ZLExciseBeginCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ZLExciseBeginCollectionViewSingleCellID forIndexPath:indexPath];
        cell.itemNumber = indexPath.item;
        cell.answerCallBack = ^(NSInteger item, NSInteger answer) {
            [weakSelf answerWithQuestionNumber:item withAnswerNumber:answer];
        };
        _exciseListModel = _singles[indexPath.item];
        cell.model = _exciseListModel;
        [cell.myTableView reloadData];
        return cell;
        
    } else {
        //多选
        ZLExciseBeginCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ZLExciseBeginCollectionViewMultipleCellID forIndexPath:indexPath];
        cell.itemNumber = indexPath.item;
        cell.answerCallBack = ^(NSInteger item, NSInteger answer) {
            [weakSelf answerWithQuestionNumber:item withAnswerNumber:answer];
        };
        _exciseListModel = _multiples[indexPath.item-_singles.count];
        cell.model = _exciseListModel;
        [cell.myTableView reloadData];
        return cell;
    }
    
}

#pragma mark - 布局
- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.mas_equalTo(35);
    }];
    [_footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.view);
        make.height.mas_equalTo(75);
    }];
    [_bgCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(_headerView.mas_bottom);
        make.bottom.equalTo(_footerView.mas_top);
    }];
}

- (void)subviewsInView
{
    //返回按钮
    [self showBackButtonWithImage:@"exam_back"];
    //导航栏
    [self showRightBarButtonItemWithImage:@"形状-1-拷贝" selectImageStr:@"形状-1"];
    //小弹窗
    [[UIApplication sharedApplication].keyWindow addSubview:self.promptView];
    [[UIApplication sharedApplication].keyWindow addSubview:self.commitView];
    [[UIApplication sharedApplication].keyWindow addSubview:self.noDataExitView];;
    //顶部视图
    [self.view addSubview:self.headerView];
    //底部视图
    [self.view addSubview:self.footerView];
    //答题视图
    [self.view addSubview:self.bgCollectionView];
}

#pragma mark - lazy load
- (ZLExciseBeginHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[ZLExciseBeginHeaderView alloc] init];
    }
    return _headerView;
}

- (ZLExciseBeginFooterView *)footerView {
    if (!_footerView) {
        _footerView = [[ZLExciseBeginFooterView alloc] init];
    }
    return _footerView;
}
- (UICollectionView *)bgCollectionView
{
    if (!_bgCollectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(kSCREEN_WIDTH, kSCREENH_HEIGHT - 110 - 64);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        _bgCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _bgCollectionView.delegate = self;
        _bgCollectionView.dataSource = self;
        _bgCollectionView.bounces = NO;
        _bgCollectionView.pagingEnabled = YES;
        _bgCollectionView.backgroundColor = [UIColor whiteColor];
        _bgCollectionView.showsHorizontalScrollIndicator = NO;
        _bgCollectionView.showsVerticalScrollIndicator = NO;
        [_bgCollectionView registerClass:[ZLExciseBeginCollectionViewCell class] forCellWithReuseIdentifier:ZLExciseBeginCollectionViewSingleCellID];
         [_bgCollectionView registerClass:[ZLExciseBeginCollectionViewCell class] forCellWithReuseIdentifier:ZLExciseBeginCollectionViewMultipleCellID];
    }
    return _bgCollectionView;
}
- (ZLExamBeginExitPromptView *)promptView {
    if (!_promptView) {
        _promptView = [[ZLExamBeginExitPromptView alloc] initWithFrame:kSCREEN_BOUNDS];
    }
    return _promptView;
}
- (ZLExamBeginSheetCommitView *)commitView {
    if (!_commitView) {
        _commitView = [[ZLExamBeginSheetCommitView alloc] initWithFrame:(CGRect){0, 0, kSCREEN_WIDTH, kSCREENH_HEIGHT}];
    }
    return _commitView;
}

- (ZLExamBeginExitPromptView *)noDataExitView
{
    if (!_noDataExitView) {
        _noDataExitView = [[ZLExamBeginExitPromptView alloc] initWithFrame:kSCREEN_BOUNDS];
        _noDataExitView.contentLbl.text = @"退出练习";
        _noDataExitView.cancelBtn.hidden = YES;
        _noDataExitView.line1.hidden = YES;
        [_noDataExitView.enterBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(_noDataExitView.whiteBgView);
            make.height.mas_equalTo(kCX_Scale(55));
        }];
    }
    return _noDataExitView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
